// page/CardInfo/CardInfo.js
const http = require("../../../utils/http")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    listdata: null,//元数据
    yancinun: false,//延迟渲染判断
    staffdata: [],//服务顾问数组
    disabled: true,//文本框禁用
    staffname: '',//服务顾问
    indate: '',//激活时间
    carexplain: '',//卡说明
    discmount: '',//赠送
    remainamount: '',//面额度
    cardrealamount: '',//实额度
    activstatus: 1//延迟参数开卡激活状态   1==立即激活,2==延迟激活
  },
  formSubmit(e) {
    //提交
    http.postRequest('/mini/v1/vip/add_document', {
      owner_id: this.data.listdata.owner.id,
      staff_id: this.data.staffname,
      card_tem_id: this.data.listdata.card_tem_id,
      card_remain_amount: this.data.remainamount,
      card_real_amount: this.data.cardrealamount,
      indate: this.data.listdata.is_forever,
      is_forever: this.data.listdata.is_forever,
      activate_status: this.data.indate == 0 ? "1" : "2",
      activate_expires: this.data.indate,
      document_id: this.data.listdata.id,
    }, res => {

    })
  },
  jejisuan(e) {
    //面额计算
    this.setData({
      remainamount: parseInt(e.detail.value || 0) + parseInt(this.data.cardrealamount),
    })
  },
  yanchi() {//延迟激活切换
    this.setData({
      indate: 0,
      yancinun: !this.data.yancinun,
    })
  },
  xiugai() {
    this.setData({//文本框禁用
      disabled: !this.data.disabled
    })
  },
  bindPickerChange: function (e) {//服务顾问选择器
    this.setData({
      staffname: this.data.staffdata[e.detail.value].id,
      index: e.detail.value
    })
  },
  // 显示遮罩层
  showModal: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  // 隐藏遮罩层
  hideModal: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  jumpOrdin() {
    this.showModal()
  },
  closeModal() {
    this.hideModal()
  },
  jumpUser(e) {
    let owner_id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/classify/child/user?id=${owner_id}`,
      // url: '/pages/classify/child/user',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    http.postRequest('/mini/v1/vip/document_info', {
      document_id: options.id,
      document_number: options.docnumber
    }, res => {
      let { data } = res
      this.setData({
        listdata: data,//元数据
        staffname: data.staff.name,//服务顾问
        indate: data.card_tem.activate_expires,//激活时间
        carexplain: data.card_tem.explain,//卡说明
        discmount: data.discounts_amount,//赠送金额
        cardrealamount: data.card_real_amount,//实金额
        remainamount: data.card_remain_amount,//面额
      })
    })
  },
})